home *** CD-ROM | disk | FTP | other *** search
- ******* util.lib/clamp ************************************************
- *
- * NAME
- * clamp -- constrain a longword between two values
- *
- * SYNOPSIS
- * newval = clamp( minval, val, maxval )
- * D0 d0 d1 d2
- *
- * LONG __asm clamp( register __D0 LONG, register __D1 LONG,
- * register __d2 LONG );
- *
- * FUNCTION
- * This function takes a longword input, and forces it to be between
- * to values. If it is lower than the minimum value, then the minimum
- * value is returned. If it is higher than the maximum value, then
- * the maximum value is returned. Otherwise, the original value is
- * returned.
- *
- * If the minimum value is higher than the maximum, then the maximum
- * value is always returned.
- *
- * INPUTS
- * minval - the lower bound of the constraint
- * val - the value to be limited
- * maxval - the upper bound of the constraint
- *
- * RESULT
- * newval - the constrained value
- *
- * EXAMPLE
- *
- * NOTES
- * Like other things, this might be better as an inline function.
- *
- * BUGS
- *
- * SEE ALSO
- *
- *****************************************************************************
- * Written by Talin
- *
- SECTION text,CODE
-
- xdef _clamp
-
- _clamp: cmp.l d0,d1 ; find the higher of d0 and d1
- blt.s 1$
- move.l d1,d0
- 1$ cmp.l d0,d2 ; find the lower of d2 and d0
- bgt.s 2$
- move.l d2,d0
- 2$ rts
-
- end
-